const Sequelize = require('sequelize');
module.exports = function (sequelize, DataTypes) {
  return sequelize.define('m_roles', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true,
      comment: 'auto id'
    },
    tenant_id: {
      type: DataTypes.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: '租户id'
    },
    role_name: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: '角色名称'
    },
    rights: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: '权限'
    },
    hash: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '权限哈希值'
    },
    tenant_hash: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '租户权限哈希值'
    }
  }, {
    sequelize,
    tableName: 'm_roles',
    timestamps: false,
    freezeTableName: true,
    indexes: [
      {
        name: 'PRIMARY',
        unique: true,
        using: 'BTREE',
        fields: [
          { name: 'id' }
        ]
      },
      {
        name: 'idx_tenant_id',
        using: 'BTREE',
        fields: [
          { name: 'tenant_id' }
        ]
      },
      {
        name: 'idx_hash',
        using: 'BTREE',
        fields: [
          { name: 'hash' }
        ]
      },
      {
        name: 'idx_tenant_hash',
        using: 'BTREE',
        fields: [
          { name: 'tenant_hash' }
        ]
      }
    ]
  });
};
